package com.qiusuo0226.platform.property;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * 服务配置绑定类
 * @author qiusuo
 * @date 2023/3/17 15:18
 */
@Component
@Slf4j
@Data
public class ServerProperty {

    @Autowired
    private Environment environment;

    /**
     * 项目激活环境
     */
    @Value("${spring.profiles.active}")
    private String activeProfiles;

    /**
     * 项目根路径
     */
    @Value("${server.servlet.context-path}")
    private String contextPath;

    /**
     * 项目端口号
     */
    @Value("${server.port}")
    private String port;

    /**
     * 项目名称
     */
    @Value("${spring.application.name:default}")
    private String applicationName;

    public Integer getPort() {
        if (StringUtils.isBlank(port)) {
            port = environment.getProperty("server.port");
        }
        return Integer.valueOf(port);
    }
}
